$(function () {
    let form = layui.form
    // 1.获取用户id,并数据回填
    let id = new URLSearchParams(location.search).get('id')
    function lodeUserInfo() {
        $.ajax({
            url: '/admin/users/' + id,
            success: function (res) {
                if (res.status === 0) {
                    form.val('editForm', res.data)
                } else {
                    layer.msg(res.message)
                }
            }
       })
    }
    lodeUserInfo()

    // 2.表单提交
    $('.layui-form').on('submit', function (e) {
        e.preventDefault()
        let data = $(this).serialize()
        $.ajax({
            type: 'PUT',
            url: '/admin/users',
            data: data,
            success: function (res) {
                    layer.msg(res.message)
            }
        })
    })
})